import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
// 引入多个动态路由模块--随便起的变量名
import approvalsRouter from './modules/approvals'
import departmentsRouter from './modules/departments'
import employeesRouter from './modules/employees'
import permissionRouter from './modules/permission'
import attendancesRouter from './modules/attendances'
import salarysRouter from './modules/salarys'
import settingRouter from './modules/setting'
import socialRouter from './modules/social'
// 动态路由
export const asyncRoutes = [
  // 组合动态路由模块
  departmentsRouter, // 组织架构
  settingRouter, // 公司设置
  employeesRouter, // 员工管理
  permissionRouter, // 权限管理
  approvalsRouter, // 审批
  attendancesRouter, // 考勤
  salarysRouter, // 工资
  socialRouter// 社保
]
/**
 * constantRoutes 静态路由
 */
export const constantRoutes = [

  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true // 只要将 hidden 设置为true,就不会再左侧菜单展示
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/excel',
    component: Layout,
    hidden: true,
    children: [{
      path: '',
      name: 'excel',
      component: () => import('@/views/excel/upload-excel.vue')
      // meta: { title: 'excel' }
    }]
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard', // 重定向 首页
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      // meta 字段：路由元信息，就是自定义的属性
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  }

  // 404 page must be placed at the end !!!
  // { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  // routes: [...constantRoutes, ...asyncRoutes] // 配置路由规则
  routes: [...constantRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  // 再次将路由进行实例化，在退出的时候调用这个方法
  // 就相当于将路由调换成一个新的路由对象
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
